﻿using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.Extensions.DependencyInjection;

namespace System {
    public static class ThemesConfigureServices
    {
        /// <summary>
        /// 添加Theme服务
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static void AddThemes(this IServiceCollection services)
        {
            services.AddSingleton<IThemeContext, ThemeContext>();
            //themes support
            services.Configure<RazorViewEngineOptions>(options =>
            {
                options.ViewLocationExpanders.Add(new ThemeableViewLocationExpander());
            });
        }

        /// <summary>
        /// 启用Theme中间件
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseThemes(this IApplicationBuilder builder)
        {
            return builder.UseMiddleware<ThemeMiddleware>();
        }
    }
}